package com.controller.company;

import com.dao.EditDao;
import com.dao.imp.EditDaoimpl;
import com.entity.Job;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
@WebServlet("/EditPublishJobState")
public class EditPublishJobState extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        doPost(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        resp.setCharacterEncoding("utf-8");
        resp.setContentType("text/html;charset=utf-8");
        String state = req.getParameter("state");
        String jobId = req.getParameter("jobId");
        System.out.println("state = " + state);


        Job job = new Job();
        job.setJobId(Integer.parseInt(jobId));
        job.setState(state);

        EditDao editDao  = new EditDaoimpl();
        int i =editDao.EditPublishJobState(job);
        System.out.println("editPublishjobstate-i = " + i);
        if(i==1){
            resp.getWriter().write("success");
        }else{
            resp.getWriter().write("fail");
        }

    }
}
